package com.future.controller;

import com.future.domain.Result;
import com.future.service.ChatMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "聊天信息管理")
public class ChatMessageController {
    @Autowired
    private ChatMessageService messageService;
    /**
     * 获取聊天室消息(游标分页)
     *
     * @param roomId   聊天室ID
     * @param lastMessageId 游标：上一页最后一条消息的id,首次查询可以不传
     * @param pageSize 每页大小
     * @return 历史消息列表
     */
    @GetMapping("/getmessage")
    @ApiOperation("获取聊天室消息")
    public Result getMessages(
            @RequestParam("roomId") String roomId,
            @RequestParam(value = "lastMessageId", required = false)String lastMessageId,
            @RequestParam(defaultValue = "20") Integer pageSize) {
        return messageService.getMessages(roomId, lastMessageId, pageSize);
    }
    /**
     * 获取用户在指定聊天室的未读消息数
     * @param roomId 聊天室ID
     * @return 未读消息数
     */
    @GetMapping("/unread-count")
    @ApiOperation("获取用户在指定聊天室的未读消息数")
    public Result getUnreadCountByRoom( @RequestParam String roomId) {
        return messageService.getUnrendCountByRoom(roomId);
    }
    /**
     * 获取用户所有聊天室的未读消息数
     * @return 各聊天室未读消息数(按房间ID分组)
     */
    @GetMapping("/all-unread-counts")
    @ApiOperation("获取用户所有聊天室的未读消息数")
    public Result getAllUnreadCounts() {
        return messageService.getAllUnreadCounts();
    }
    /**
     * 清零用户在指定聊天室的未读消息数
     * @param roomId 聊天室ID
     * @return 操作结果
     */
    @DeleteMapping("/clear-unread")
    @ApiOperation("清零用户在指定聊天室的未读消息数")
    public Result clearUnReadCount( @RequestParam String roomId) {
        return messageService.clearUnReadCount(roomId);
    }
    /**
     * 删除单条聊天记录
     */
    @DeleteMapping("/delect-message")
    public Result deleteChatMessage(@RequestParam("chatmessageId")String chatmessageId)
    {
        return messageService.deleteChatMessage(chatmessageId);
    }

}
